import type { Ref } from 'vue';
import { ref, watchEffect } from 'vue';

interface props {
    seat: Ref<seat>;
}
export default function usePhase(props: props): usePhaseReturn {
    const phaseUseEnd = ref(false);
    return {
        round() {
            // let player;
            // if (props.isTurnOut.value === true) {
            //     this.isTurnOut = false;
            //     player = this.getNextPlayer(this.seat);
            // } else {
            //     this.setCurrent();
            //     player = this;
            // }
            window.e.create('phase', {
                target: props.seat.value,
                num: 2,
            });
        },
        // setCurrent() {
        //     this.current = true;
        //     this.setCurrentPlayer(this.seat);
        // },
        // skipPhase(phase) {
        //     remove(
        //         this.$parent.EventPool,
        //         i => i.player === this.seat && i.name.indexOf(phase) !== -1,
        //     );
        // },
        phaseJudgeContent(e) {
            console.log('判定阶段内容');
            // if (!this.num('j')) {
            //     e.cards = this.judge();
            // }
            // return e;
        },
        phaseDrawContent(e) {
            console.log('摸牌阶段内容');
            // this.draw(e.num);
            console.log(`摸了${e.num}张牌`);
        },
        phaseUseContent(e) {
            return new Promise(res => {
                console.log('出牌阶段内容');
                watchEffect(() => {
                    if (phaseUseEnd.value) {
                        phaseUseEnd.value = false;
                        res();
                    }
                });
                setTimeout(() => {
                    console.log('犹豫了2s后，还是什么都没干，出牌阶段结束');
                    phaseUseEnd.value = true;
                }, 2000);
            });
        },
        phaseDiscardContent(e) {
            console.log('弃牌阶段内容');
            // const num = this.num('h') - this.maxHandCard;
            // if (num > 0) {
            //     e.cards = await this.chooseToDiscard(num);
            // }
            // return e;
        },
    };
}
